package com.chansos.dubbogo.hessian_generator;

import java.util.HashMap;
import java.util.Map;

public class FileInfo {
    private String path;
    private StringBuilder stringBuffer = new StringBuilder();
    private String defaultStructName;

    private int packageStartIndex;
    private int packageEndIndex;
    private boolean hasInitFunction;
    private int initFuncEndIndex;
    private int initFuncStartIndex;
    private int initFuncStatementStartIndex;
    private boolean hasHessianImport;

    private int appendOffset;

    Map<String, GoStruct> goStructMap = new HashMap<>();

    public FileInfo(String path) {
        this.path = path;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public StringBuilder getStringBuffer() {
        return stringBuffer;
    }

    public void setStringBuffer(StringBuilder stringBuffer) {
        this.stringBuffer = stringBuffer;
    }

    public boolean isHasInitFunction() {
        return hasInitFunction;
    }

    public void setHasInitFunction(boolean hasInitFunction) {
        this.hasInitFunction = hasInitFunction;
    }

    public int getInitFuncEndIndex() {
        return initFuncEndIndex;
    }

    public void setInitFuncEndIndex(int initFuncEndIndex) {
        this.initFuncEndIndex = initFuncEndIndex;
    }

    public int getInitFuncStartIndex() {
        return initFuncStartIndex;
    }

    public void setInitFuncStartIndex(int initFuncStartIndex) {
        this.initFuncStartIndex = initFuncStartIndex;
    }

    public int getInitFuncStatementStartIndex() {
        return initFuncStatementStartIndex;
    }

    public void setInitFuncStatementStartIndex(int initFuncStatementStartIndex) {
        this.initFuncStatementStartIndex = initFuncStatementStartIndex;
    }

    public boolean isHasHessianImport() {
        return hasHessianImport;
    }

    public void setHasHessianImport(boolean hasHessianImport) {
        this.hasHessianImport = hasHessianImport;
    }

    public Map<String, GoStruct> getGoStructMap() {
        return goStructMap;
    }

    public void setGoStructMap(Map<String, GoStruct> goStructMap) {
        this.goStructMap = goStructMap;
    }

    public GoStruct getGoStruct(String name) {
        GoStruct value = goStructMap.getOrDefault(name, new GoStruct(name));
        goStructMap.put(name, value);
        return value;
    }

    public int getAppendOffset() {
        return appendOffset;
    }

    public void setAppendOffset(int appendOffset) {
        this.appendOffset = appendOffset;
    }

    public int getPackageStartIndex() {
        return packageStartIndex;
    }

    public void setPackageStartIndex(int packageStartIndex) {
        this.packageStartIndex = packageStartIndex;
    }

    public int getPackageEndIndex() {
        return packageEndIndex;
    }

    public void setPackageEndIndex(int packageEndIndex) {
        this.packageEndIndex = packageEndIndex;
    }

    public String getDefaultStructName() {
        return defaultStructName;
    }

    public void setDefaultStructName(String defaultStructName) {
        this.defaultStructName = defaultStructName;
    }

    public void keepOnlyStruct(String defaultStructName) {
        Map<String, GoStruct> structMap = new HashMap<>();
        structMap.put(defaultStructName,getGoStruct(defaultStructName));
        goStructMap = structMap;
    }
}
